package com.emotionalEnvelope.edu.controller.email;

import com.emotionalEnvelope.edu.core.RestResponse;
import com.emotionalEnvelope.edu.dto.MyMsgDto;
import com.emotionalEnvelope.edu.model.Email;
import com.emotionalEnvelope.edu.service.IEmailService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 消息管理
 *
 * @Description
 * @Author lqq
 * @Date 2023/05/09 23:39
 */
@RestController
@RequestMapping("/api/msg")
public class EmailController {

    @Resource
    private IEmailService messagesService;

    @PostMapping("/send")
    public RestResponse<String> send(@Validated @RequestBody Email params) {
        return messagesService.toSend(params);
    }

    @GetMapping("/showMyMsg")
    public RestResponse<List<MyMsgDto>> showMyMsg(@Validated @RequestParam Long id) {
        return messagesService.showMyMessage(id);
    }

    @GetMapping("/allRead")
    public RestResponse<String> allRead(@Validated @RequestParam Long userId) {
        return messagesService.allRead(userId);
    }

    @PostMapping("/reply")
    public RestResponse<String> reply(@Validated @RequestBody Email params) {
        return messagesService.reply(params);
    }

    @GetMapping("/del")
    public RestResponse<List<MyMsgDto>> withdraw(@Validated @RequestParam Long id) {
        new Email().deleteById(id);
        return RestResponse.ok();
    }

    @GetMapping("/read")
    public RestResponse<String> read(@Validated @RequestParam Long id) {
        return messagesService.read(id);
    }
}
